package org.com.system.util.dao;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.web.context.WebApplicationContext;


public class BaseDao<E>{

	private WebApplicationContext applicationContext=null;
	
	public BaseDao(WebApplicationContext applicationContext){
		this.applicationContext=applicationContext;
	}
	
	/**
	 * 得到以jdbc实现的dao对象
	 * @return
	 */
	public JdbcDao<E> getJDao(){
		JdbcDao<E> jdbcDao=new JdbcDao<E>();
		jdbcDao.setQueryRuner(applicationContext.getBean("dataSource_client", DataSource.class));
		return jdbcDao;
	}
	/**
	 * 得到以spring的jdbcTemplate实现的dao对象
	 * @return
	 */
	public SpringDao<E> getSDao(){
		SpringDao<E> springDao=new SpringDao<E>();
		springDao.setDataSource(applicationContext.getBean("dataSource_system",DataSource.class));
		return new SpringDao<E>();
	}
	/**
	 * 得到以hibernate实现的dao对象
	 * @return
	 */
	public HibernateDao<E> getHDao(){
		HibernateDao<E> hiberDao=new HibernateDao<E>();
		hiberDao.setSessionFactory((SessionFactory)applicationContext.getBean("sessionFactory"));
		return hiberDao;
	}
	
}
